package Bean;

import com.sun.istack.NotNull;

import javax.persistence.*;
import java.util.LinkedList;

@Entity
@Table(name = "bookrecommend", schema = "bookloansystem", catalog = "")
public class Bookrecommend {
    int id;
    String data;

    @Id
    @Column(name = "id")
    @NotNull
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }




    @Basic
    @Column(name = "data")
    @NotNull
    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }




    public void formatData(LinkedList<Integer> data) {
        StringBuilder stringBuilder=new StringBuilder();
        if (data.size()==0){
            this.data="";
            return;
        }
        for (Integer datum : data) {
            stringBuilder.append(datum);
            stringBuilder.append(" ");
        }
        stringBuilder.deleteCharAt(stringBuilder.length()-1);//删除最后一个空格
        this.data=stringBuilder.toString();
    }
    public LinkedList<Integer> formatData(){
        String middle[]=data.split(" ");
        LinkedList<Integer> res=new LinkedList<>();
        for (String s : middle) {
            try {//异常数据舍弃
                int num=Integer.valueOf(s);
                res.addLast(num);
            } catch (Exception e) {
            }
        }
        return res;
    }
}
